package demo.java.springboot.mybatis.sys.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import demo.java.springboot.mybatis.sys.dao.UserDao;
import demo.java.springboot.mybatis.sys.po.User;
import demo.java.springboot.mybatis.sys.service.UserService;

@Service
@Transactional
public class UserServiceImpl implements UserService {

	private static final Logger LOG = LoggerFactory.getLogger(UserServiceImpl.class);
	
	@Resource
	private UserDao userDao;
	
	@Override
	public User getById(String id) {
		return userDao.findById(id);
	}

	@Override
	public List<User> getAll() {
		// 设置分页参数：获取第2页数据，每页最大行数为2
		PageHelper.startPage(2, 2);
		
		// 获取分页结果：包括总数和当前页行数据集合
		Page<User> u = (Page<User>)userDao.findAll();
		// 获取总数
		LOG.info("用户总数" + u.getTotal());
		// 获取当前页数据集合
		return u.getResult();
	}

}
